﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BoggleWpfTest
{
    /// <summary>
    /// Interaction logic for BogglePiece.xaml
    /// </summary>
    public partial class BogglePiece : UserControl
    {
        private Tuple<int, int> coordinate;

        SolidColorBrush maroonBrush = new SolidColorBrush(Colors.Maroon);
        SolidColorBrush blackBrush = new SolidColorBrush(Colors.Black);
        SolidColorBrush grayBrush = new SolidColorBrush(Colors.Gray);

        private bool clicked = false;
        
        public BogglePiece(int c, int r)
        {
            coordinate = new Tuple<int, int>(c, r);
            
            InitializeComponent();
        }

        public void SetLabel(char c)
        {
            if (c == 'Q')
                this.pieceLabel.Content = "" + c + 'u';
            else
                this.pieceLabel.Content = c;
        }

        public string GetLabel()
        {
            return this.pieceLabel.ToString();
        }

        public void ResetPiece()
        {
            clicked = false;
            this.rect1.Fill = blackBrush;
        }

        public Tuple<int, int> GetCoordinate()
        {
            return coordinate;
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!clicked)
            {
                clicked = true;
                this.rect1.Fill = grayBrush;
            }
            else
            {
                clicked = false;
                this.rect1.Fill = blackBrush;
            }
        }

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            if (!clicked)
            {
                this.rect1.Fill = maroonBrush;
            }
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!clicked)
            {
                this.rect1.Fill = blackBrush;
            }
        }
    }
}
